package com.ymy.thinking.in.spring.dependency.injection;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * Java 注解 配置构造器注入
 *
 * @author Ringo
 * @date 2021/9/29 18:17
 */
public class AnnotationDependencyConstructorInjectionDemo {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext =
                new AnnotationConfigApplicationContext(AnnotationDependencyConstructorInjectionDemo.class);
        System.out.println(applicationContext.getBean(UserHolder.class));
    }

    @Bean
    public User user() {
        return new User("李连杰", 20);
    }

    @Bean
    public User user1() {
        return new User("李连杰1", 20);
    }

    @Bean
    public UserHolder userHolder(@Qualifier("user1") User u) {
        return new UserHolder(u);
    }

}
